#include<bits/stdc++.h>

using namespace std;

const int N = 1e5 + 10;
int a[N];
int main()
{
	int n; cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	int ret = 0;

	for(int i = 0; i <= n; i++)
		if(a[i] < a[i + 1]) ret += a[i + 1] - a[i];


	cout << ret << endl;
	
	return 0;
} 
